//
//  LLMusicVM.swift
//  新印象
//
//  Created by wyl on 2016/12/21.
//  Copyright © 2016年 魏延龙. All rights reserved.
//

import UIKit

class LLMusicVM: NSObject {
    
    var alldata = [LLMusicModel]()
    
    var filename : String!
    
    
    // MARK: 搜索音乐
    func query(completeSuccess: @escaping ()-> Void,completeFailed: @escaping ()-> Void) {
        let url = "http://apis.baidu.com/geekery/music/query"
        let parameters = ["s":filename]
        LLNetManager.netGet(url: url, parameters: parameters as Dictionary<String, AnyObject>, completionHandlerSuccess: { (dic) in
            let dataArr = (dic["data"] as! Dictionary<String, AnyObject>)["data"] as! Array<AnyObject>
            for data in dataArr{
                let model = LLMusicModel()
                model.filename = data["filename"] as? String
                model.album_name = data["album_name"] as? String
                model.duration = data["duration"] as? Int
                model.extname = data["extname"] as? String
                model.hash = data["hash"] as? String
                model.singername = data["singername"] as? String
                self.alldata.append(model)
            }
            completeSuccess()
        }) { (Error) in
            completeFailed()
        }
    }
    func numOfRow() -> Int{
        return self.alldata.count
    }
    
}
